<template>
  <div class="page">
    <canvas-backgroud class="stars"></canvas-backgroud>

    <div class="border">
      <div class="canvas">
        <div class="title">{{title}}</div>
        <textfield ref="usernameTextfield" class="textfield" :placeholder="'username'"></textfield>
        <textfield ref="passwordTextfield" class="textfield" :placeholder="'password'"></textfield>

        <div class="button-canvas">
          <my-button class="button" :title="'Login'" @click="onLoginButtonClick"></my-button>
        </div>

      </div>
    </div>
  </div>
</template>

<script>


  import zhRequest from '../../utils/geralt_common/network_function';
  import manageInterface from '../../interface/manageInterface';
  import manageConstant from '../../constant/manageConstant';

  let textfield = resolve => {
    require(['../../components/input/normal_textfield'],resolve);
  };
  let myButton = resolve => {
  	require(['../../components/buttom'],resolve);
  }
  let canvasBackgroud = resolve => {
  	require(['../../components/canvas_background/stars'],resolve)
  }

  console.log('manageConstant',manageConstant);


  export default {
    name: "login",
    components:{
      canvasBackgroud,
      textfield,
      myButton,
    },
    data(){
      return {
        title: manageConstant.blogName,
        isLoading: false,
        height: 677,
        width: 375,
      }
    },

    methods:{
    	onLoginButtonClick(){
    		console.log('login button clicked',this.$refs.usernameTextfield.getText());

    		this.isLoading = true;
        zhRequest.post(
          manageInterface.adminLoginUrl,
          {
            username: this.$refs.usernameTextfield.getText(),
            password: this.$refs.passwordTextfield.getText(),
          },
          (response)=>{
            this.isLoading = false;
            if(response.data.result.result=='success'){
            	this.$router.push('/manage/edit');
            }
          },
          (error)=>{
            this.isLoading = false;
            console.log('error');
          }
        )
      },

    }
  }
</script>

<style lang="less" scoped>

  .stars {
    position: fixed;
    top: 0;
    left: 0;
  }

  .page{
    background-color: rgba(0, 0, 0, 0.85);
    width: 100%;
    height: 100%;
  }

  .border{
    padding-top: 120px;
    width: 250px;
    margin-left: auto;
    margin-right: auto;

  }
  .canvas{
    border-radius: 5px;
    box-shadow: 0 2px 2px rgba(0,0,0,0.2);
    padding: 8px 8px 8px 8px;
    height: 300px;
    background-color: rgba(255,255,255,0.9);
  }
  .title{
    padding-top: 20px;
    font-size: 3rem;
  }
  .textfield{
    margin-top: 10px;
  }

  .button-canvas{
    padding-top: 30px;
    width: 100%;
    height: 30px;
  }
  .button{
    margin-left: auto;
    margin-right: auto;
  }
</style>
